using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Rensselaer_Event_Finder
{
    public partial class SignupForm : Form
    {
        public SignupForm()
        {
            InitializeComponent();
        }

        private void submitBtn_Click(object sender, EventArgs e)
        {
            if (passwordBox.Text == confirmpwBox.Text)
            {
                User newUser = new User();
                newUser.Username = usernameBox.Text;
                newUser.Password = passwordBox.Text;
                Globals.getUserService().save(newUser);
                Globals.CurrentUser = newUser;
            }
            else
            {
                MessageBox.Show("Passwords do not match...", "Error");
                return;
            }
            Globals.CurrentUser = Globals.getUserService().login(usernameBox.Text, passwordBox.Text);
            if (Globals.CurrentUser != null)
            {
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            else
            {
                MessageBox.Show("Problem creating user...", "Error");
            }
        }

        private void cancelBtn_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }
    }
}